function Game(el) {

    // 保存地图对象
    this.el = document.querySelector(el)

    // 搞地图
    this.map = new Map(this.el) //将地图标签对象传递给map构造函数,里面设置宽度,高度
    this.map.create()

    // 搞食物
    this.food = new Food(this.el)
    this.food.create()

    // 搞蛇
    this.snake = new Snake(this.el)
    this.snake.create()
}

Game.prototype.start = function () {
    setInterval(() => {
        // 蛇移动
        this.snake.move()
        // 判断吃食
        let snakeX = this.snake.snakeObj[0].x * 20
        let snakeY = this.snake.snakeObj[0].y * 20
        let foodX = this.food.foodX
        let foodY = this.food.foodY

        if (snakeX == foodX && snakeY == foodY) {
            // alert('真香')
            let last = this.snake.snakeObj[this.snake.snakeObj.length - 1]

            this.snake.snakeObj.push({
                x: last.x,
                y: last.y,
                color: last.color,
                el: null
            })
            this.snake.create()
            this.food.move()
        }
    }, 100)
    document.addEventListener('keydown', (e) => {
        e = e || window.event
        console.log(e.keyCode);
        switch (e.keyCode) {
            case 38:
                this.snake.direction = 'top'
                break;
            case 40:
                this.snake.direction = 'bottom'
                break;
            case 37:
                if (this.snake.direction == 'right') {
                    // alert('游戏结束')
                }
                this.snake.direction = 'left'
                break;
            case 39:
                this.snake.direction = 'right'
                break;
            default:
                break;
        }
    })
}